<a href='https://github.com/angular/angular.js/edit/v1.4.x/src/ng/filter.js?message=docs($filterProvider)%3A%20describe%20your%20change...#L14' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.4.7/src/ng/filter.js#L14' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">$filterProvider</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
  <li>
    <a href="api/ng/service/$filter">- $filter</a>
  </li>

    <li>
      - provider in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>Filters are just functions which transform input to an output. However filters need to be
Dependency Injected. To achieve this a filter definition consists of a factory function which is
annotated with dependencies and is responsible for creating a filter function.</p>
<div class="alert alert-warning">
<strong>Note:</strong> Filter names must be valid angular <a href="guide/expression"><code>Expressions</code></a> identifiers, such as <code>uppercase</code> or <code>orderBy</code>.
Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
your filters, then you can use capitalization (<code>myappSubsectionFilterx</code>) or underscores
(<code>myapp_subsection_filterx</code>).
</div>

<pre><code class="lang-js">// Filter registration
function MyModule($provide, $filterProvider) {
  // create a service to demonstrate injection (not always needed)
  $provide.value(&#39;greet&#39;, function(name){
    return &#39;Hello &#39; + name + &#39;!&#39;;
  });

  // register a filter factory which uses the
  // greet service to demonstrate DI.
  $filterProvider.register(&#39;greet&#39;, function(greet){
    // return the filter function which uses the greet service
    // to generate salutation
    return function(text) {
      // filters need to be forgiving so check input validity
      return text &amp;&amp; greet(text) || text;
    };
  });
}
</code></pre>
<p>The filter function is registered with the <code>$injector</code> under the filter name suffix with
<code>Filter</code>.</p>
<pre><code class="lang-js">it(&#39;should be the same instance&#39;, inject(
  function($filterProvider) {
    $filterProvider.register(&#39;reverse&#39;, function(){
      return ...;
    });
  },
  function($filter, reverseFilter) {
    expect($filter(&#39;reverse&#39;)).toBe(reverseFilter);
  });
</code></pre>
<p>For more information about how angular filters work, and how to create your own filters, see
<a href="guide/filter">Filters</a> in the Angular Developer Guide.</p>

</div>




<div>
  

    

  

  
<h2>Methods</h2>
<ul class="methods">
  <li id="register">
    <h3><p><code>register(name, factory);</code></p>

</h3>
    <div></div>

    
    <h4>Parameters</h4>
    
<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        name
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-string">string</a><a href="" class="label type-hint type-hint-object">Object</a>
      </td>
      <td>
        <p>Name of the filter function, or an object map of filters where
   the keys are the filter names and the values are the filter factories.</p>
   <div class="alert alert-warning">
   <strong>Note:</strong> Filter names must be valid angular <a href="guide/expression"><code>Expressions</code></a> identifiers, such as <code>uppercase</code> or <code>orderBy</code>.
   Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
   your filters, then you can use capitalization (<code>myappSubsectionFilterx</code>) or underscores
   (<code>myapp_subsection_filterx</code>).
   </div>
        
      </td>
    </tr>
    
    <tr>
      <td>
        factory
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-function">Function</a>
      </td>
      <td>
        <p>If the first argument was a string, a factory function for the filter to be registered.</p>

        
      </td>
    </tr>
    
  </tbody>
</table>

    

    
    
    
    <h4>Returns</h4>
    <table class="variables-matrix return-arguments">
  <tr>
    <td><a href="" class="label type-hint type-hint-object">Object</a></td>
    <td><p>Registered filter instance, or if a map of filters was provided then a map
   of the registered filter instances.</p>
</td>
  </tr>
</table>
    

  </li>
  </ul>
  
  



  
</div>


